<template>
  <div class="photoinfo-container">
    <h1>{{photoinfo.title}}</h1>
    <p class="subtitle">
      <span>发表时间:{{photoinfo.add_time|dateFormat}}</span>
      <span>点击:{{photoinfo.click}}次</span>
    </p>
    <hr>

    <!-- 缩略图 -->
    <div class="thumbs">
      <vue-preview :slides="slide1" @close="handleClose"></vue-preview>
    </div>

    <!-- 图片内容区域 -->
    <div class="content" v-html="photoinfo.content"></div>

    <!-- 放置现成的评论子组件 -->
    <cmt-box :id="this.id"></cmt-box>
  </div>
</template>

<script>
import { Toast } from "mint-ui";

import comment from "../subcomponents/comment.vue";

export default {
  data() {
    return {
      id: this.$route.params.id,
      photoinfo: {},
      slide1: []
    };
  },
  created() {
    this.getPhotoInfo();
    this.getPhotominInfo();
  },
  methods: {
    getPhotoInfo() {
      this.$ajax
        .get("/photoinfo/", {
          params: {
            ID: this.id
          }
        })
        .then(response => {
          this.photoinfo = response.data.message[0];
          //   console.log(response.data.message);
        })
        .catch(error => {
          console.log(error);
          Toast({
            message: "获取图片内容失败..."
          });
        });
    },
    getPhotominInfo() {
      this.$ajax
        .get("/getphotomininfo/", {
          params: {
            ID: this.id
          }
        })
        .then(response => {
          //循环每个图片数据,补全图片的宽和高
          response.data.message.forEach(item => {
            item.msrc = item.src;
            item.w = 600;
            item.h = 400;
          });
          this.slide1 = response.data.message;
          // console.log(this.slide1);
        })
        .catch(error => {
          console.log(error);
          Toast({
            message: "获取缩略图图片失败..."
          });
        });
    },
    handleClose() {
      console.log("close event");
    }
  },
  components: {
    "cmt-box": comment
  }
};
</script>

<style lang="scss" scoped>
.photoinfo-container {
  padding: 3px;
  h1 {
    color: #26a2ff;
    font-size: 15px;
    text-align: center;
    margin: 15px 0;
  }
  .subtitle {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
  }
  .content {
    font-size: 13px;
    line-height: 30px;
    text-align: center;
  }
}

.thumbs {
  /deep/ .my-gallery {
    display: flex;
    flex-wrap: wrap;
    figure {
      width: 30%;
      margin: 5px;
      
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
}
</style>


